﻿using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Validation.StringValues;

namespace Xms.Abp.Validation.StringValues;

[Serializable]
[ValueValidator("OPTIONS")]
public class OptionsValueValidator<TOption> : ValueValidatorBase
{
    protected IEnumerable<TOption> Options { get; }
    public OptionsValueValidator(params TOption[] options)
    {
        Options = options;
    }
    public OptionsValueValidator(IEnumerable<TOption> options)
    {
        Options = options;
    }
    public override bool IsValid(object value)
    {
        if (value != null && value is TOption option)
        {
            return Options.Contains(option);
        }
        return false;
    }
}
